package com.zxt.content.copywriting.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxt.content.common.Bean.Result;
import com.zxt.content.common.utils.ObjectUtils;
import com.zxt.content.copywriting.model.PrivateCopywriting;
import com.zxt.content.copywriting.req.PrivateCopywritingDTO;
import com.zxt.content.copywriting.req.PrivateCopywritingQueryDTO;
import com.zxt.content.copywriting.resp.PrivateCopywritingVO;
import com.zxt.content.copywriting.service.IPrivateCopywritingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zxt
 */
@Slf4j
@RequestMapping("/copywriting/privateCopywriting/")
@RestController
@AllArgsConstructor
@Api(tags = "私有文案管理接口")
public class PrivateCopywritingController {

    private final IPrivateCopywritingService privateCopywritingService;

    @GetMapping("/query")
    @ApiOperation(value = "用户测试接口", notes = "用户测试接口")
    private Result<List<PrivateCopywritingVO>> query() {
        return Result.newSuccess(privateCopywritingService.queryList());
    }

    @PostMapping("/addOrUpdate")
    @ApiOperation(value = "添加/修改", notes = "添加/修改")
    private Result addOrUpdate(@RequestBody @Validated PrivateCopywritingDTO dto) {
        privateCopywritingService.saveOrEdit(dto);
        return Result.newSuccess();
    }

    @PostMapping("/page/list")
    @ApiOperation(value = "私有文案分页列表", notes = "私有文案分页列表")
    private Result<Page<PrivateCopywritingVO>> queryList(@RequestBody PrivateCopywritingQueryDTO dto) {
        ObjectUtils.removeStringSpaces(dto);
        return Result.newSuccess(privateCopywritingService.pageList(dto));
    }

    @GetMapping("/delete")
    @ApiOperation(value = "私有文案批量删除", notes = "私有文案批量删除")
    private Result delete(@RequestParam("ids") List<Long> ids) {
        privateCopywritingService.batchDelete(ids);
        return Result.newSuccess();
    }

    @GetMapping("/uploadCopywriting")
    @ApiOperation(value = "上传私有文案到公共文案", notes = "上传私有文案到公共文案")
    private Result uploadCopywriting(@RequestParam("ids") List<Long> ids) {
        privateCopywritingService.uploadCopywriting(ids);
        return Result.newSuccess();
    }
}
